package com.wenhai.spring.bean.definition;

import com.wenhai.spring.bean.factory.DefaultUserFactory;
import com.wenhai.spring.bean.factory.UserFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @Author:wenhai
 * @Description: 初始化
 * @Date:2020/3/7
 */
@Configuration
public class BeanInitializationDemo {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(BeanInitializationDemo.class);
        annotationConfigApplicationContext.refresh();
        System.out.println(annotationConfigApplicationContext.getBean(UserFactory.class));
        annotationConfigApplicationContext.close();
    }


    @Lazy
    @Bean(initMethod = "initMethod",destroyMethod = "destroyCustomDestroyMethod")
    public UserFactory userFactory() {
        return new DefaultUserFactory();
    }
}
